/**
 * @author yzhou2
 */
var RTQ_L2MarketDepth_SettingPanel=function(callback,config){
    this.callback={
        onModeChanged:null,//function(v){}
        onQuoteChecked:null//function(v){}
    };
    this.config={
        selectMode:'MBO',
        isShowQuote:true,
        container:$(document.body)
    };
    if(callback){
        $.extend(this.callback,callback);
    }
    if(config){
        $.extend(this.config,config);
    }
    this.el=null;
    this.modeRatingRBtn=null;
    this.quoteShowCheckBox=null;
    this.html='<div class="rtq-l2-mkdp-setting"><div class="l2-mode"></div><div class="quote-show"></div><div>';
    this.init();
};
RTQ_L2MarketDepth_SettingPanel.prototype={
    init:function(){
        this.el=$(this.html).appendTo(this.config.container);
        this._createModelRBtn();
        this._createQuoteShowCheckBox();
    },
    selectModelRBtn:function(k){
        var btn;
        for(var b in this.modeRatingRBtn.btns){
            btn=this.modeRatingRBtn.btns[b];
            if(b==k){
                btn.select();
            }else{
                btn.inverse();
            }
        }
    },
    disableModelRBtn:function(ks,selected){//['MBP']
        if(ks == null) {
            selected=selected===false?false:true;
            this.modeRatingRBtn.disable(selected);
        }else {
            var btn,map;
            for (var b in this.modeRatingRBtn.btns) {
                btn = this.modeRatingRBtn.btns[b];
                if($.inArray(b,ks)>-1){
                    btn.disable(true);
                }else{
                    btn.disable(false);
                }
            }
        }
    },
    _createModelRBtn:function(){
        var self=this;
        var modeData=[{
            txt: "Market By Order",
            val: "MBO"
        }, {
            txt: "Market By Price",
            val: "MBP"
        }, {
            txt: "Market By MMID",
            val: "MBM"
        }];
        this.modeRatingRBtn=new Util.ButtonGroup(this.el.find('.l2-mode'), modeData, {
            onClick:function(v){
                if(typeof self.callback.onModeChanged=='function'){
                    self.callback.onModeChanged(v); 
                }
            }
        },{
            vertical:true,
            inverse:false
        });
        this.modeRatingRBtn.btns[this.config.selectMode].select();
    },
    _createQuoteShowCheckBox:function(){
        var self=this;
        this.quoteShowCheckBox = new Util.ButtonGroup(this.el.find('.quote-show'), [{txt:'Show Quote',val:'show'}], {
            onClick:function(v, btn){
               if(typeof self.callback.onQuoteChecked=='function'){
                    self.callback.onQuoteChecked(btn.isSelected); 
               }
            }
        },{type:'checkbox'});
        if(this.config.isShowQuote){
            this.quoteShowCheckBox.btns["show"].select();
        }
    },
    clear:function(){
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};
